package com.alinesno.cloud.initializr.starter.gateway.rest.cicd;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alinesno.cloud.common.facade.response.AjaxResult;
import com.alinesno.cloud.initializr.starter.service.IBuildProjectInfoService;

/**
 * 执行结果回调
 * 
 * @author WeiXiaoJin
 * @since 2021年6月27日 下午4:19:56
 */
@RestController
@RequestMapping("/api/jenkins/callback")
public class JenkinsCallbackRest {

	private static final Logger log = LoggerFactory.getLogger(JenkinsCallbackRest.class);

	@Autowired
	private IBuildProjectInfoService buildProjectInfoService;

	/**
	 * 任务完成回调
	 * 
	 * @param jobName
	 * @return
	 */
	@GetMapping("/finish/{jobName}")
	public AjaxResult finish(@PathVariable("jobName") String jobName) {

		log.debug("jobName = {}", jobName);

		// 删除工程
		buildProjectInfoService.deleteJenkinsJob(jobName);

		return AjaxResult.success();
	}

}
